package com.eling.elcms.travel.model;

import com.eling.elcms.basedoc.model.EnumSerializer;
import com.eling.elcms.core.dao.annotation.Between;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancer;
import com.eling.elcms.core.dao.annotation.CriteriaEnhancers;
import com.eling.elcms.core.dao.annotation.In;
import com.eling.elcms.core.dao.hibernate.OrderCriteriaEnhancer;
import com.eling.elcms.core.dao.hibernate.search.EnumBridge;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.ordermanager.model.ServicePoint;
import com.eling.elcms.privilege.service.impl.CommonPrivilegeCriteriaEnhancer;
import com.eling.elcms.system.model.CommonUser;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.hibernate.search.annotations.*;

import javax.persistence.*;
import java.util.Date;
/**
 * 福利消费券
 * @author ly
 * 
 */
@Entity
@Table(name = "travel_welfare")
@Indexed
@CriteriaEnhancers(criteriaEnhancers = {
		@CriteriaEnhancer(impl = OrderCriteriaEnhancer.class, parameter = "grantDate:desc"),
		@CriteriaEnhancer(impl = CommonPrivilegeCriteriaEnhancer.class, parameter = "servicepoint:servicePoint")})
public class WelfareConsumptionCoupon  extends BaseModel{
	
	private static final long serialVersionUID = -5482288934545384605L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@DocumentId
	@In
	private Long pkWelfarecc;
	
	/**所属服务点*/
	@ManyToOne(fetch = FetchType.LAZY)
	@In
	@JoinColumn(name = "pkServicePoint")
    @IndexedEmbedded(depth = 1)
	private ServicePoint servicePoint;
	
	/** 卡号*/
	@Column(unique = true)
	@Field
	private String cardNo;
	
	/** 余额*/
	@Column
	@Field
	private Double balance;
	
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="pkTravelContract")
    @IndexedEmbedded(depth = 1)
    private TravelContract travelContract;
    
    /** 有效日期 */
    @Column
    @Field
    @Between
    private Date effectiveDate;
    
    /** 发放日期 */
    @Column
    @Field
    @Between
    private Date grantDate;
	
	/** 返券日期 */
	@Column
	@Field
	@Between
	private Date returnDate;
	
	/** 福利消费券状态*/
	@Enumerated(EnumType.STRING)
	@In	
	@FieldBridge(impl = EnumBridge.class)
	private Status status;
	
	/** 是否发放过消费券  **/
	@Column
	@Field
	private Boolean isGrant;
	
	@Version
	private Integer version;
	
	/** 经办人 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "pkOperator")
	@IndexedEmbedded(depth = 1)
	private CommonUser operator;
	
	/** 备注 */
	@Column
	@Field
	private String remark;
	
	public CommonUser getOperator() {
		return operator;
	}

	public void setOperator(CommonUser operator) {
		this.operator = operator;
	}

	
	@JsonSerialize(using = EnumSerializer.class)
	public static enum Status {
		
		Lose("挂失"),Effective("有效"),Returned("退卡");

		private String display;
		
		Status(String display) {
			this.display = display;
		}
		
		public String getDisplay() {
			return display;
		}
	}
	
	public Long getPkWelfarecc() {
		return pkWelfarecc;
	}
	
	public void setPkWelfarecc(Long pkWelfarecc) {
		this.pkWelfarecc = pkWelfarecc;
	}

	public ServicePoint getServicePoint() {
		return servicePoint;
	}

	public void setServicePoint(ServicePoint servicePoint) {
		this.servicePoint = servicePoint;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	
	public Double getBalance() {
		return balance;
	}

	public void setBalance(Double balance) {
		this.balance = balance;
	}

	public TravelContract getTravelContract() {
		return travelContract;
	}

	public void setTravelContract(TravelContract travelContract) {
		this.travelContract = travelContract;
	}

	public Date getGrantDate() {
		return grantDate;
	}

	public void setGrantDate(Date grantDate) {
		this.grantDate = grantDate;
	}

	public Date getReturnDate() {
		return returnDate;
	}

	public void setReturnDate(Date returnDate) {
		this.returnDate = returnDate;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Boolean getIsGrant() {
		return isGrant;
	}

	public void setIsGrant(Boolean isGrant) {
		this.isGrant = isGrant;
	}

	public Date getEffectiveDate() {
		return effectiveDate;
	}

	public void setEffectiveDate(Date effectiveDate) {
		this.effectiveDate = effectiveDate;
	}
}
